<template>
  <div class="m-login-container">
    <el-row class="m-main-header-search">
      <el-form hide-required-asterisk ref="refForm" class="label-row">
        <el-row>
          <el-form-item prop="order_sn" label="订单sn">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.order_sn"
              placeholder="订单sn"
            ></el-input>
          </el-form-item>
          <el-form-item prop="compose_group_sn" label="套餐组sn">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.compose_group_sn"
              placeholder="套餐组sn"
            ></el-input>
          </el-form-item>
          <el-form-item prop="compose_group_name" label="套餐组名称">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.compose_group_name"
              placeholder="套餐组名称"
            ></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item prop="user_name" label="姓名">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.user_name"
              placeholder="姓名"
            ></el-input>
          </el-form-item>
          <el-form-item prop="phone" label="电话">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.phone"
              placeholder="电话"
            ></el-input>
          </el-form-item>

          <el-form-item prop="ip_addr" label="地址">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.ip_addr"
              placeholder="地址"
            ></el-input>
          </el-form-item>
        </el-row>

        <el-form-item prop="status" label="状态">
          <el-input
            clearable
            size="small"
            autofocus
            v-model="refFormData.status"
            placeholder="状态"
          ></el-input>
        </el-form-item>
        <el-form-item prop="origin" label="origin">
          <el-input
            clearable
            size="small"
            autofocus
            v-model="refFormData.origin"
            placeholder="origin"
          ></el-input>
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker
            v-model="time"
            size="small"
            type="daterange"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
      </el-form>
      <div class="search-btn-wrapper">
        <el-button @click="handleSearch()" type="primary" size="small">
          查询
        </el-button>
      </div>
    </el-row>
    <div class="m-main-content-body">
      <p class="contant-body-title">Spend</p>
      <el-table
        v-loading="loading"
        :data="list"
        tooltip-effect="dark"
        style="width: 100%"
        :inline="false"
        stripe
        :header-cell-style="{
          'background-color': '#E5EEFF',
        }"
      >
        <el-table-column
          prop="spend"
          label="消耗"
          :autoFit="true"
          :fitHeader="true"
        >
        </el-table-column>
        <el-table-column
          prop="cpp"
          label="cpp"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="cpm"
          label="cpm"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="country"
          label="地区"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="account_id"
          label="账户id"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="account_name"
          label="账户名称"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="time"
          label="时间"
          :autoFit="true"
          :fitHeader="true"
        >
          <template slot-scope="scope">
            {{
              scope.row.time
                ? $moment(scope.row.time).format("YYYY/MM/DD HH:mm:ss")
                : "--"
            }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="(val) => handlePageMetaChange(val, 'size')"
          @current-change="(val) => handlePageMetaChange(val, 'page')"
          :current-page="pageMeta.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageMeta.limit"
          layout="sizes, prev, next, jumper"
          :total="pageMeta.total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      list: [],
      loading: false,
      dislogSetVisible: false,
      refFormData: {},
      pageMeta: {
        page: 1,
        limit: 10,
        total: 1e10,
      },
      time: [
        this.$moment(new Date()).format("YYYY-MM-DD"),
        this.$moment(new Date()).format("YYYY-MM-DD"),
      ],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /*
     * @Desc: 获取列表
     * @params: {String}
     * @return: {Object}
     */
    async getList() {
      this.loading = true;
      const [start_time, end_time] = this.time;
      const { data } = await this.$api.roi.getTokenSpendList({
        ...this.pageMeta,
        page: this.pageMeta.page - 1,
        ...this.refFormData,
        start_time: start_time + " 00:00:00",
        end_time: end_time + " 23:59:59",
      });
      const { code, data: list } = data;
      if (code === 200) {
        this.list = list;
      }
      this.loading = false;
    },

    /*
     * @Desc:
     * @params: {String}
     * @return: {Object}
     */
    async handleSearch() {
      this.pageMeta.page = 1;
      this.getList();
    },

    /**
     * @Desc 分页
     * @params {String} val page/limit
     * @params {String} type  page/size
     * @return {Object}
     * */
    handlePageMetaChange(val, type = "size") {
      this.pageMeta[type === "size" ? "limit" : "page"] = val;
      this.getList();
    },
  },
};
</script>

<style lang="less" scoped>
.m-login-container {
  display: flex;
  .m-main-content-body {
    flex: 1;
    .el-table {
      width: auto !important;
    }
  }
}
.m-main-header-search {
  width: 348px;
  margin-right: 16px;
}
.search-btn-wrapper {
  overflow: hidden;
  margin-top: 20px;
  .el-button {
    float: right;
  }
}
</style>
